﻿using Dotnet.Utils.Utility.Threading.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;

namespace Dotnet.Utils.Utility.Threading
{
    public static class AsyncExecuterExtensions
    {
        public static Task<bool> ContainsAsync<T>(this IQueryable<T> queryable, T item, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.ContainsAsync(queryable, item, cancellationToken);
        }

        public static Task<bool> AnyAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AnyAsync(queryable, cancellationToken);
        }

        public static Task<bool> AnyAsync<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AnyAsync(queryable, predicate, cancellationToken);
        }

        public static Task<bool> AllAsync<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AllAsync(queryable, predicate, cancellationToken);
        }

        public static Task<int> CountAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.CountAsync(queryable, cancellationToken);
        }

        public static Task<int> CountAsync<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.CountAsync(queryable, predicate, cancellationToken);
        }

        public static Task<long> LongCountAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.LongCountAsync(queryable, cancellationToken);
        }

        public static Task<long> LongCountAsync<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.LongCountAsync(queryable, predicate, cancellationToken);
        }

        public static Task<T> FirstAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.FirstAsync(queryable, cancellationToken);
        }

        public static Task<T> FirstAsync<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.FirstAsync(queryable, predicate, cancellationToken);
        }

        public static Task<T> FirstOrDefaultAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.FirstOrDefaultAsync(queryable, cancellationToken);
        }

        public static Task<T> FirstOrDefaultAsync<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.FirstOrDefaultAsync(queryable, predicate, cancellationToken);
        }

        public static Task<T> LastAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.LastAsync(queryable, cancellationToken);
        }

        public static Task<T> LastAsync<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.LastAsync(queryable, predicate, cancellationToken);
        }

        public static Task<T> LastOrDefaultAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.LastOrDefaultAsync(queryable, cancellationToken);
        }

        public static Task<T> LastOrDefaultAsync<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.LastOrDefaultAsync(queryable, predicate, cancellationToken);
        }

        public static Task<T> SingleAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SingleAsync(queryable, cancellationToken);
        }

        public static Task<T> SingleAsync<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SingleAsync(queryable, predicate, cancellationToken);
        }

        public static Task<T> SingleOrDefaultAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SingleOrDefaultAsync(queryable, cancellationToken);
        }

        public static Task<T> SingleOrDefaultAsync<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> predicate, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SingleOrDefaultAsync(queryable, predicate, cancellationToken);
        }

        public static Task<T> MinAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.MinAsync(queryable, cancellationToken);
        }

        public static Task<TResult> MinAsync<T, TResult>(this IQueryable<T> queryable, Expression<Func<T, TResult>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.MinAsync(queryable, selector, cancellationToken);
        }

        public static Task<T> MaxAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.MaxAsync(queryable, cancellationToken);
        }

        public static Task<TResult> MaxAsync<T, TResult>(this IQueryable<T> queryable, Expression<Func<T, TResult>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.MaxAsync(queryable, selector, cancellationToken);
        }

        public static Task<decimal> SumAsync(this IQueryable<decimal> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, cancellationToken);
        }

        public static Task<decimal?> SumAsync(this IQueryable<decimal?> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, cancellationToken);
        }

        public static Task<decimal> SumAsync<T>(this IQueryable<T> queryable, Expression<Func<T, decimal>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, selector, cancellationToken);
        }

        public static Task<decimal?> SumAsync<T>(this IQueryable<T> queryable, Expression<Func<T, decimal?>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, selector, cancellationToken);
        }

        public static Task<int> SumAsync(this IQueryable<int> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, cancellationToken);
        }

        public static Task<int?> SumAsync(this IQueryable<int?> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, cancellationToken);
        }

        public static Task<int> SumAsync<T>(this IQueryable<T> queryable, Expression<Func<T, int>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, selector, cancellationToken);
        }

        public static Task<int?> SumAsync<T>(this IQueryable<T> queryable, Expression<Func<T, int?>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, selector, cancellationToken);
        }

        public static Task<long> SumAsync(this IQueryable<long> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, cancellationToken);
        }

        public static Task<long?> SumAsync(this IQueryable<long?> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, cancellationToken);
        }

        public static Task<long> SumAsync<T>(this IQueryable<T> queryable, Expression<Func<T, long>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, selector, cancellationToken);
        }

        public static Task<long?> SumAsync<T>(this IQueryable<T> queryable, Expression<Func<T, long?>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, selector, cancellationToken);
        }

        public static Task<double> SumAsync(this IQueryable<double> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, cancellationToken);
        }

        public static Task<double?> SumAsync(this IQueryable<double?> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, cancellationToken);
        }

        public static Task<double> SumAsync<T>(this IQueryable<T> queryable, Expression<Func<T, double>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, selector, cancellationToken);
        }

        public static Task<double?> SumAsync<T>(this IQueryable<T> queryable, Expression<Func<T, double?>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, selector, cancellationToken);
        }

        public static Task<float> SumAsync(this IQueryable<float> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, cancellationToken);
        }

        public static Task<float?> SumAsync(this IQueryable<float?> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, cancellationToken);
        }

        public static Task<float> SumAsync<T>(this IQueryable<T> queryable, Expression<Func<T, float>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, selector, cancellationToken);
        }

        public static Task<float?> SumAsync<T>(this IQueryable<T> queryable, Expression<Func<T, float?>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.SumAsync(queryable, selector, cancellationToken);
        }

        public static Task<decimal> AverageAsync(this IQueryable<decimal> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, cancellationToken);
        }

        public static Task<decimal?> AverageAsync(this IQueryable<decimal?> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, cancellationToken);
        }

        public static Task<decimal> AverageAsync<T>(this IQueryable<T> queryable, Expression<Func<T, decimal>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, selector, cancellationToken);
        }

        public static Task<decimal?> AverageAsync<T>(this IQueryable<T> queryable, Expression<Func<T, decimal?>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, selector, cancellationToken);
        }

        public static Task<double> AverageAsync(this IQueryable<int> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, cancellationToken);
        }

        public static Task<double?> AverageAsync(this IQueryable<int?> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, cancellationToken);
        }

        public static Task<double> AverageAsync<T>(this IQueryable<T> queryable, Expression<Func<T, int>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, selector, cancellationToken);
        }

        public static Task<double?> AverageAsync<T>(this IQueryable<T> queryable, Expression<Func<T, int?>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, selector, cancellationToken);
        }

        public static Task<double> AverageAsync(this IQueryable<long> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, cancellationToken);
        }

        public static Task<double?> AverageAsync(this IQueryable<long?> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, cancellationToken);
        }

        public static Task<double> AverageAsync<T>(this IQueryable<T> queryable, Expression<Func<T, long>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, selector, cancellationToken);
        }

        public static Task<double?> AverageAsync<T>(this IQueryable<T> queryable, Expression<Func<T, long?>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, selector, cancellationToken);
        }

        public static Task<double> AverageAsync(this IQueryable<double> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, cancellationToken);
        }

        public static Task<double?> AverageAsync(this IQueryable<double?> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, cancellationToken);
        }

        public static Task<double> AverageAsync<T>(this IQueryable<T> queryable, Expression<Func<T, double>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, selector, cancellationToken);
        }

        public static Task<double?> AverageAsync<T>(this IQueryable<T> queryable, Expression<Func<T, double?>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, selector, cancellationToken);
        }

        public static Task<float> AverageAsync(this IQueryable<float> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, cancellationToken);
        }

        public static Task<float?> AverageAsync(this IQueryable<float?> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, cancellationToken);
        }

        public static Task<float> AverageAsync<T>(this IQueryable<T> queryable, Expression<Func<T, float>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, selector, cancellationToken);
        }

        public static Task<float?> AverageAsync<T>(this IQueryable<T> queryable, Expression<Func<T, float?>> selector, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.AverageAsync(queryable, selector, cancellationToken);
        }

        public static Task<List<T>> ToListAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.ToListAsync(queryable, cancellationToken);
        }

        public static Task<T[]> ToArrayAsync<T>(this IQueryable<T> queryable, IAsyncQueryableExecuter asyncExecuter, CancellationToken cancellationToken = default(CancellationToken))
        {
            return asyncExecuter.ToArrayAsync(queryable, cancellationToken);
        }
    }
}